package org.al.poc.sockets;

import java.io.IOException;
import java.net.ServerSocket;

public abstract class AbstractServer implements Runnable {
	
	
	protected int port;
	protected int nbThreads;
	
	
	
	public AbstractServer(int port, int nbThreads) {
		this.port = port;
		this.nbThreads = nbThreads;
	}
	

	public abstract void logServerRunning();
	public abstract void startNewServerThread(ServerSocket ss);
	// typiquement : new Thread (new ServerThread(ss)).start();
	

	
	@Override
	public void run() {

		try {
			ServerSocket ss = new ServerSocket(port);
			logServerRunning();

			for (int i = 0 ; i < nbThreads ; ++i) {
				startNewServerThread(ss);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
